package com.lll.drools.service;

import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;

import com.lll.drools.entity.TaxiFare;
import com.lll.drools.entity.TaxiRide;

/**
 * Description: 费用计算服务接口<br/>
 *
 * @author liulonglong
 * @taskId <br/>
 * @Date 2019/11/18 15:37
 * @Version 1.0
 */
@Service
public class TaxiFareCalculatorService {

    /**
     * kie
     */
    @Autowired
    private KieContainer kieContainer;

    public BigDecimal calculateTaxiFare(TaxiRide taxiRide, TaxiFare taxiFare) {
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.setGlobal("rideFare", taxiFare);
        kieSession.insert(taxiRide);
        kieSession.fireAllRules();
        // 清理会话以避免内存泄漏。
        kieSession.dispose();
        return taxiFare.total();
    }
}
